home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 27 / Mac Magazin and MacEasy Magazine CD - Issue 27.iso / Grafik & Text / Sans-Faute⁄Grammaire ƒ / Adaptateurs / Sources des scripts (anglais) / Vérification WordPerfect® 3 < prev   
Text File  |  1996-02-20  |  3KB  |  87 lines

  1. set kMaxDocSize to 10000 -- max number of characters of a document for checking it in one time
  2. set kMaxCheckingSFG to 32000 -- max number of characters that Sans-Faute/Grammaire can check
  3. set knbParagraphMaxToCheck to 25 -- max number of paragraphs sent to Sans-Faute/Grammaire
  4.  
  5.  
  6. tell application "WordPerfect"
  7.     set FrontDocPresent to exists front document
  8. end tell
  9.  
  10. if FrontDocPresent then
  11.     
  12.     set endParagraphIdx to 0
  13.     tell application "WordPerfect"
  14.         set nbParagraph to count paragraph of front document
  15.     end tell
  16.     repeat while endParagraphIdx < nbParagraph
  17.         -- try to collect a maximum of paragraphs
  18.         set paragraphIdx to endParagraphIdx + 1
  19.         tell application "WordPerfect"
  20.             set paragraphSize to count character of paragraph paragraphIdx of front document
  21.             if paragraphSize = 1 then
  22.                 set dummy to paragraph paragraphIdx of front document
  23.                 set paragraphSize to count character of dummy
  24.             end if
  25.         end tell
  26.         if paragraphSize > kMaxCheckingSFG then
  27.             display dialog "Le paragraphe " & paragraphIdx & " dépasse 32000 caractères. Sans-Faute/Grammaire ne peut pas le vérifier !"
  28.         end if
  29.         repeat while (paragraphIdx ≤ nbParagraph) and (paragraphSize > kMaxCheckingSFG)
  30.             set paragraphIdx to paragraphIdx + 1
  31.             if paragraphIdx ≤ nbParagraph then
  32.                 tell application "WordPerfect"
  33.                     set paragraphSize to count character of paragraph paragraphIdx of front document
  34.                     if paragraphSize = 1 then
  35.                         set dummy to paragraph paragraphIdx of front document
  36.                         set paragraphSize to count character of dummy
  37.                     end if
  38.                 end tell
  39.                 if paragraphSize > kMaxCheckingSFG then
  40.                     display dialog "Le paragraphe " & paragraphIdx & " dépasse 32000 caractères. Sans-Faute/Grammaire ne peut pas le vérifier !"
  41.                 end if
  42.             end if
  43.         end repeat
  44.         set startParagraphIdx to paragraphIdx
  45.         
  46.         set bunchSize to 0
  47.         set nbparagraphBunch to 0
  48.         set objToCheck to {}
  49.         repeat while (paragraphIdx ≤ nbParagraph) and (nbparagraphBunch < knbParagraphMaxToCheck) and (bunchSize + paragraphSize ≤ kMaxDocSize)
  50.             --   (paragraphSize ≤ kMaxCheckingSFG) is implicit
  51.             set bunchSize to bunchSize + paragraphSize
  52.             if paragraphSize > 0 then
  53.                 set objToCheck to objToCheck & {a reference to the paragraph paragraphIdx of front document}
  54.                 set nbparagraphBunch to nbparagraphBunch + 1
  55.             end if
  56.             
  57.             set paragraphIdx to paragraphIdx + 1
  58.             if paragraphIdx ≤ nbParagraph then
  59.                 tell application "WordPerfect"
  60.                     set paragraphSize to count character of paragraph paragraphIdx of front document
  61.                     if paragraphSize = 1 then
  62.                         set dummy to paragraph paragraphIdx of front document
  63.                         set paragraphSize to count character of dummy
  64.                     end if
  65.                 end tell
  66.             end if
  67.         end repeat
  68.         
  69.         if (bunchSize = 0) and (paragraphIdx ≤ nbParagraph) and (paragraphSize ≤ kMaxCheckingSFG) then
  70.             set objToCheck to objToCheck & {a reference to the paragraph paragraphIdx of front document}
  71.             set endParagraphIdx to paragraphIdx
  72.             set bunchSize to paragraphSize
  73.         else
  74.             set endParagraphIdx to paragraphIdx - 1
  75.         end if
  76.         
  77.         if bunchSize > 0 then -- cas be zero if the end of the document contains only paragraphs > 32000
  78.             -- tell Sans-Faute/Grammaire to check the content of the list of references and made changes in Application WordPerfect®
  79.             tell application "Sans-Faute/Grammaire 2"
  80.                 Checking objToCheck ClientAddress Application "WordPerfect"
  81.             end tell
  82.         end if
  83.     end repeat
  84. else
  85.     display dialog "Aucun document n'est ouvert dans WordPerfect® 3 !"
  86. end if
  87.